package com.junxonline.common.util;

import com.google.gson.Gson;
import com.junxonline.common.dao.vo.ResultVO;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * @author JunX
 * @ClassName: ShiroFilterUtils
 * @Description: Shiro过滤器工具类
 */

public class ShiroFilterUtils {

    /**
     * 输出返回的JSON结果
     * @param servletResponse
     * @param resultVO
     */
    public static void out(ServletResponse servletResponse, ResultVO resultVO) {
        PrintWriter out = null;
        try {
            HttpServletResponse response = (HttpServletResponse) servletResponse;
            response.setCharacterEncoding("UTF-8");
            response.setHeader("Access-Control-Allow-Origin","*");
//            response.setHeader("Access-Control-Allow-Origin","http://www.junxtec.com");
            response.setHeader("Access-Control-Allow-Methods","POST,GET");
            response.setHeader("Access-Control-Max-Age","3600");
            response.setHeader("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept");
            response.setHeader("","");response.setHeader("","");
            out = response.getWriter();
            Gson gson = new Gson();
            out.println(gson.toJson(resultVO));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != out) {
                out.flush();
                out.close();
            }
        }
    }

}
